package com.module.check;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import base.util.Page;

import com.module.check.manager.CheckTaskManager;
import com.module.check.vo.CheckTask;
import com.module.organization.manager.OrganizationManager;
import com.module.organization.vo.Organization;
import com.module.prms.manager.UserManager;
import com.module.prms.vo.PrmsUser;
import com.module.sys.LoginSession;

public class CheckTaskService {

	public Page list(CheckTask bean, Integer start, Integer limit)
			throws Exception {
		Page page = new Page();
		page.setStart(start);
		page.setLimit(limit);
		bean.setUserId(LoginSession.getUserid());
		CheckTaskManager manager = CheckTaskManager.getInstance();
		page = manager.list(page, bean);
		return page;
	}

	public Map<String,Object> remove(Long id)throws Exception{       
		Map<String,Object> map = new HashMap<String,Object>();
		CheckTaskManager manager = CheckTaskManager.getInstance();
		map = manager.delete(id);
		return map;
		
	}	


	public Map<String,Object> save(CheckTask bean)throws Exception{
		bean.setOrgId(LoginSession.getOrgid());
		Map<String,Object> map = new HashMap<String,Object>();
		CheckTaskManager manager = CheckTaskManager.getInstance();
		map = manager.add(bean);
		return map;

	} 
	

	public CheckTask findById(Long id)throws Exception{
		CheckTask bean = new CheckTask();
		CheckTaskManager manager = CheckTaskManager.getInstance();
		bean = manager.findById(id);
		return bean;
	}
	
	/**
	 * 任务分配人员列表
	 * @param orgList
	 * @param userList
	 * @return
	 * @throws Exception
	 */
	public List taskDistributing()throws Exception{
		List<Organization> returnList = new ArrayList<Organization>();
		
//		List<Organization> orglist = LoginSession.getOrgtree();
		OrganizationManager orgm = OrganizationManager.getInstance();
		List<Organization> orglist = orgm.findOrgByPId(LoginSession.getOrgid());
		UserManager userManager = UserManager.getInstance();
		for (Organization org : orglist) {
			String orgid = org.getId();
			List<PrmsUser>userList = userManager.findUserByOrgId(orgid);//用户列表
			org.setUserlist(userList);
			returnList.add(org);
		}

		return returnList;
	}
	/**
	 * 任务分配
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public Map<String,Object> taskAllot(Long id)throws Exception{       
		Map<String,Object> map = new HashMap<String,Object>();
		CheckTaskManager manager = CheckTaskManager.getInstance();
		map = manager.taskAllot(id);
		return map;
		
	}	
}
